Jupyter at Bryn Mawr College |
|||
Public notebooks: /services/public/dblank / CS245 Programming Languages / 2016-Fall / Notebooks |
And, oh, by the way, I hate having those closing parens jump into existence automatically. Let's turn them off!
In the file ~/.jupyter/custom/custom.js
, add these lines:
require(['notebook/js/codecell'], function (codecell) {
codecell.CodeCell.options_default.cm_config.autoCloseBrackets = false;
});
%%javascript
IPython.CodeCell.options_default.cm_config.autoCloseBrackets = false;
(define my-member
(lambda (item lyst)
(cond
((null? lyst) #f)
((eq? item (car lyst)) #t)
(else (my-member item (cdr lyst))))))
(my-member 'a '()) ;; -> #f
(my-member 'a '(a)) ;; -> #t
(my-member 'a '(a b c)) ;; -> #t
(my-member 'c '(a b c)) ;; -> #t
(my-member 'd '(a b c)) ;; -> #f
(my-member 'b '(a (b) c)) ;; -> #f
(define my-length
(lambda (lyst)
(cond
((null? lyst) 0)
(#t (+ 1 (my-length (cdr lyst)))))))
(my-length '()) ;; -> 0
(my-length '(100)) ;; -> 1
(my-length '(100 (200) 300)) ;; -> 3
(define my-sum
(lambda (lyst)
(cond
[(null? lyst) 0]
[else (+ (car lyst)
(my-sum (cdr lyst)))])))
(my-sum '()) ;; -> 0
(my-sum '(23)) ;; -> 23
(my-sum '(1 2 3)) ;; -> 6
(my-sum '(1 2 3 (4 (5) 6) 7))
(define sum*
(trace-lambda "sum*" (lyst)
(cond
[(null? lyst) 0]
[(list? (car lyst)) (+ (sum* (car lyst))
(sum* (cdr lyst)))]
[else (+ (car lyst)
(sum* (cdr lyst)))])))
(sum* '(1 2 3 (4 (5) 6) 7)) ;; -> 28